package com.itheima.Array.sort;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-08-19 13:25
 **/
public class ShellSort {
//    shell排序
    public static void shellSort(int[] nums) {
        int n=nums.length;
        for (int gap = n/2; gap >0; gap/=2) {
            for (int i = gap; i < n; i++) {
                int key=nums[i];
//                int j=i;
                int Index=i-gap;
// 对每个子数组进行插入排序
                while (Index>=0&& nums[Index]>key){
                    nums[Index+gap]=nums[Index];
                    Index-=gap;
                }
                nums[Index+gap]=key;
            }
        }
    }
}
